package com.yy.jhl.util;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.bigkoo.pickerview.adapter.WheelAdapter;
import com.bigkoo.pickerview.lib.WheelView;
import com.orhanobut.dialogplus.ViewHolder;
import com.yy.common.commonwidget.PickerView;
import com.yy.jhl.R;
import com.yy.jhl.bean.ProductInfo;
import com.yy.jhl.interfaces.CommonCallBack;
import com.orhanobut.dialogplus.DialogPlus;
import com.yy.jhl.interfaces.EnsureCallBack;
import com.yy.jhl.interfaces.PictureCallBack;
import com.yy.jhl.interfaces.ProductCallBack;

import java.util.ArrayList;
import java.util.List;

/** 选择弹出框
 * Created by Ellis.Li on 2017/6/21.
 */

public class DialogUtil {

    /**
     * 确定提示框
     * @param context
     * @param title
     * @param commonCallBack
     * @return
     */
    public static DialogPlus showEnsureDialogView(
            final Context context, String title, final CommonCallBack commonCallBack) {
        if (context == null) {
            return null;
        }
        final DialogPlus dialogPlus = DialogPlus.newDialog(context)
                .setContentHolder(new ViewHolder(R.layout.dialog_order_done))
                .setGravity(Gravity.CENTER).setCancelable(false)
                .setBackgroundColorResId(context.getResources().getColor(R.color.transparent))
                .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                .setContentWidth(ViewGroup.LayoutParams.WRAP_CONTENT)
                .create();
        View view = dialogPlus.getHolderView();
        final TextView title_text = (TextView) view
                .findViewById(R.id.title_text);
        final TextView ensureText = (TextView) view
                .findViewById(R.id.ensure_text);
        final TextView cancelText = (TextView) view
                .findViewById(R.id.cancel_text);
        title_text.setText(title);
        ensureText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
                commonCallBack.getCallBack();
            }
        });
        cancelText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
            }
        });
        dialogPlus.show();
        return dialogPlus;
    }

    /**
     * 确定提示框
     * @param context
     * @param title
     * @param commonCallBack
     * @return
     */
    public static DialogPlus showOnlyEnsureDialogView(
            final Context context, String title, final CommonCallBack commonCallBack) {
        if (context == null) {
            return null;
        }
        final DialogPlus dialogPlus = DialogPlus.newDialog(context)
                .setContentHolder(new ViewHolder(R.layout.dialog_ensure))
                .setGravity(Gravity.CENTER).setCancelable(false)
                .setBackgroundColorResId(context.getResources().getColor(R.color.transparent))
                .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                .setContentWidth(ViewGroup.LayoutParams.WRAP_CONTENT)
                .create();
        View view = dialogPlus.getHolderView();
        final TextView title_text = (TextView) view
                .findViewById(R.id.title_text);
        final TextView ensureText = (TextView) view
                .findViewById(R.id.ensure_text);
        title_text.setText(title);
        ensureText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
                commonCallBack.getCallBack();
            }
        });
        dialogPlus.show();
        return dialogPlus;
    }

    /**
     * 选择框
     * @param context
     * @param commonCallBack
     * @return
     */
    public static DialogPlus showSelectDialogView(
            final Context context, final List<ProductInfo> productInfoList,final ProductCallBack commonCallBack) {
        if (context == null) {
            return null;
        }
        final DialogPlus dialogPlus = DialogPlus.newDialog(context)
                .setContentHolder(new ViewHolder(R.layout.dialog_select))
                .setGravity(Gravity.BOTTOM).setCancelable(false)
                .setBackgroundColorResId(context.getResources().getColor(R.color.transparent))
                .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                .setContentWidth(ViewGroup.LayoutParams.MATCH_PARENT)
                .create();
        View view = dialogPlus.getHolderView();
        final TextView cancelText = (TextView) view
                .findViewById(R.id.cancel_text);
        final TextView ensureText = (TextView) view
                .findViewById(R.id.ensure_text);
        final WheelView numPicker = (WheelView) view
                .findViewById(R.id.picker_view);
        final List<String> dataList = new ArrayList<>();
        for (int i=0;i<productInfoList.size();i++){
            dataList.add(productInfoList.get(i).getItem_name()+"-"+productInfoList.get(i).getModel());
        }
        numPicker.setCurrentItem(0);
        numPicker.setCyclic(false);
        numPicker.setAdapter(new ArrayWheelAdapter<String>(dataList));

//        numPicker.setData(dataList);
//        numPicker.setSelected(0);
//        productInfo[0] = productInfoList.get(0);
//        numPicker.setOnSelectListener(new PickerView.onSelectListener() {
//            @Override
//            public void onSelect(String text) {
//                for (int i=0;i<productInfoList.size();i++){
//                    if (text.equals(productInfoList.get(i).getItem_name()+"-"+productInfoList.get(i).getModel())){
//                        productInfo[0] = productInfoList.get(i);
//                        break;
//                    }
//                }
//            }
//        });
        ensureText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
                commonCallBack.getCallBack(productInfoList.get(numPicker.getCurrentItem()));
            }
        });
        cancelText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
            }
        });
        dialogPlus.show();
        return dialogPlus;
    }
    /**
     * 选择审核结果框
     * @param context
     * @param commonCallBack
     * @return
     */
    public static DialogPlus showSelectCheckReusltDialogView(
            final Context context,final EnsureCallBack commonCallBack) {
        if (context == null) {
            return null;
        }
        final DialogPlus dialogPlus = DialogPlus.newDialog(context)
                .setContentHolder(new ViewHolder(R.layout.dialog_select))
                .setGravity(Gravity.BOTTOM).setCancelable(false)
                .setBackgroundColorResId(context.getResources().getColor(R.color.transparent))
                .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                .setContentWidth(ViewGroup.LayoutParams.MATCH_PARENT)
                .create();
        View view = dialogPlus.getHolderView();
        final TextView cancelText = (TextView) view
                .findViewById(R.id.cancel_text);
        final TextView ensureText = (TextView) view
                .findViewById(R.id.ensure_text);
        final WheelView numPicker = (WheelView) view
                .findViewById(R.id.picker_view);
        final List<String> dataList = new ArrayList<>();
        dataList.add("通过");
        dataList.add("不通过");
        numPicker.setCurrentItem(0);
        numPicker.setCyclic(false);
        numPicker.setAdapter(new ArrayWheelAdapter<String>(dataList));
        ensureText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
                commonCallBack.getCallBack(numPicker.getCurrentItem());
            }
        });
        cancelText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
            }
        });
        dialogPlus.show();
        return dialogPlus;
    }

    /**
     * 确定提示框
     * @param context
     * @param commonCallBack
     * @return
     */
    public static DialogPlus showSaveDialogView(
            final Context context, final CommonCallBack commonCallBack) {
        if (context == null) {
            return null;
        }
        final DialogPlus dialogPlus = DialogPlus.newDialog(context)
                .setContentHolder(new ViewHolder(R.layout.dialog_save))
                .setGravity(Gravity.BOTTOM).setCancelable(false)
                .setBackgroundColorResId(context.getResources().getColor(R.color.transparent))
                .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                .setContentWidth(ViewGroup.LayoutParams.MATCH_PARENT)
                .create();
        View view = dialogPlus.getHolderView();
        final TextView save_text = (TextView) view
                .findViewById(R.id.save_text);
        final TextView cancel_text = (TextView) view
                .findViewById(R.id.cancel_text);
        save_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
                commonCallBack.getCallBack();
            }
        });
        cancel_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
            }
        });
        dialogPlus.show();
        return dialogPlus;
    }


    /**
     * @param context
     * @param commonCallBack
     * @return
     */
    public static DialogPlus showPictureDialogView(
            final Context context,boolean isShowAlbum, final PictureCallBack commonCallBack) {
        if (context == null) {
            return null;
        }
        final DialogPlus dialogPlus = DialogPlus.newDialog(context)
                .setContentHolder(new ViewHolder(R.layout.dialog_picture_view))
                .setGravity(Gravity.BOTTOM).setCancelable(false)
                .setBackgroundColorResId(context.getResources().getColor(R.color.transparent))
                .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                .setContentWidth(ViewGroup.LayoutParams.MATCH_PARENT)
                .create();
        View view = dialogPlus.getHolderView();
        final TextView dialog_album = (TextView) view
                .findViewById(R.id.dialog_album);
        if (isShowAlbum){
            dialog_album.setVisibility(View.VISIBLE);
        }else {
            dialog_album.setVisibility(View.GONE);
        }
        final TextView take_picture = (TextView) view
                .findViewById(R.id.take_picture);
        final TextView cancel_text = (TextView) view
                .findViewById(R.id.cancel_text);
        //拍照
        dialog_album.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
                commonCallBack.getCallBack(1);
            }
        });
        //相册选择
        take_picture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
                commonCallBack.getCallBack(2);
            }
        });
        cancel_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
            }
        });
        dialogPlus.show();
        return dialogPlus;
    }


    /**
     * @param context
     * @param commonCallBack
     * @return
     */
    public static DialogPlus showInviteDialogView(
            final Context context,final  boolean isShowMovie,final PictureCallBack commonCallBack) {
        if (context == null) {
            return null;
        }
        final DialogPlus dialogPlus = DialogPlus.newDialog(context)
                .setContentHolder(new ViewHolder(R.layout.dialog_picture_view))
                .setGravity(Gravity.BOTTOM).setCancelable(false)
                .setBackgroundColorResId(context.getResources().getColor(R.color.transparent))
                .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                .setContentWidth(ViewGroup.LayoutParams.MATCH_PARENT)
                .create();
        View view = dialogPlus.getHolderView();
        final TextView dialog_album = (TextView) view
                .findViewById(R.id.dialog_album);
        dialog_album.setText("拍照");
        final TextView take_picture = (TextView) view
                .findViewById(R.id.take_picture);
        take_picture.setText("拍摄");
        if (isShowMovie){
            take_picture.setVisibility(View.VISIBLE);
        }else {
            take_picture.setVisibility(View.GONE);
        }
        final TextView cancel_text = (TextView) view
                .findViewById(R.id.cancel_text);
        //拍照
        dialog_album.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
                commonCallBack.getCallBack(1);
            }
        });
        //拍摄
        take_picture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
                commonCallBack.getCallBack(2);
            }
        });
        cancel_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogPlus.dismiss();
            }
        });
        dialogPlus.show();
        return dialogPlus;
    }

}
